Skip to content

Reorganize tctl commands to not require an auth client by default#48894

Merged
vapopov merged 14 commits intomasterfrom
vapopov/reorgonize-tctl-commands
Dec 17, 2024
Merged

Reorganize tctl commands to not require an auth client by default#48894
vapopov merged 14 commits intomasterfrom
vapopov/reorgonize-tctl-commands

Conversation

@vapopov
Copy link
Copy Markdown
Contributor

@vapopov vapopov commented Nov 13, 2024

In this PR added ability to declare tctl commands which not required auth client such as version command

Related: #47692 (comment)

@github-actions github-actions Bot requested a review from Joerger November 13, 2024 14:37
@github-actions github-actions Bot added tctl tctl - Teleport admin tool tsh tsh - Teleport's command line tool for logging into nodes running Teleport. labels Nov 13, 2024
@github-actions github-actions Bot requested a review from r0mant November 13, 2024 14:37
@vapopov vapopov force-pushed the vapopov/reorgonize-tctl-commands branch from ceef55e to 3d57ff8 Compare November 13, 2024 14:37
@vapopov vapopov force-pushed the vapopov/reorgonize-tctl-commands branch from 3d57ff8 to fa9f372 Compare November 13, 2024 14:39
@zmb3
Copy link
Copy Markdown
Collaborator

zmb3 commented Nov 13, 2024

I don't love this approach but I'm struggling to come up with a better idea at the moment.. 🤔

@vapopov
Copy link
Copy Markdown
Contributor Author

vapopov commented Nov 13, 2024

I don't love this approach but I'm struggling to come up with a better idea at the moment.. 🤔

@zmb3 I tried couple other options but they also look not perfect, like to make auth client initialization as lazy loading so only commands which requires auth going to init connection, and another one - not return error if auth client failed to init, so in commands client might be nil

TryRun(ctx context.Context, cmd string, client *authclient.Client)

Copy link
Copy Markdown
Contributor

@rosstimothy rosstimothy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Zac, I'm not particularly fond of splitting up the commands. We could potentially expand on your suggestion to have the client be lazily constructed and instead of

TryRun(ctx context.Context, cmd string, client *authclient.Client)

we could do

TryRun(ctx context.Context, cmd string, clientFunc func() *authclient.Client)

In that scenario, the logic of building the client can stay where it is, but only be executed if the command requires an authenticated connection to the cluster.

Comment thread tool/tctl/common/tctl.go Outdated
Comment thread tool/tctl/common/tctl.go Outdated
Comment thread tool/tctl/common/cmds.go Outdated
@vapopov vapopov added the no-changelog Indicates that a PR does not require a changelog entry label Nov 15, 2024
@vapopov
Copy link
Copy Markdown
Contributor Author

vapopov commented Nov 15, 2024

I've refactored to have separate auth client initialization after command matching
commands that do not require an authentication client: tctl version|top|fido2|touchid|webauthnwin

@vapopov vapopov requested review from rosstimothy and zmb3 November 18, 2024 21:50
Copy link
Copy Markdown
Collaborator

@zmb3 zmb3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm liking this approach better. 👍

Comment thread tool/tctl/common/acl_command.go Outdated
Comment thread tool/tctl/common/auth_command.go Outdated
switch cmd {
case a.authGenerate.FullCommand():
err = a.GenerateKeys(ctx, client)
client, clientClose, err := clientFunc(ctx)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of repeated code here. Would it be simpler to run the clientFunc prior to the switch?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we init auth client (start checking profile folder, establish connection, request ping) before actual matching the command has to be run. We need to identify what command it is by FullCommand() and then each command decides if auth client is required

Comment thread tool/tctl/common/client/auth.go Outdated
Comment thread tool/tctl/common/client/auth.go Outdated
Comment thread tool/tctl/common/config/profile.go Outdated
@vapopov vapopov force-pushed the vapopov/reorgonize-tctl-commands branch from 7240ab5 to b6fe948 Compare November 21, 2024 19:02
@vapopov vapopov requested a review from zmb3 November 25, 2024 19:44
@vapopov
Copy link
Copy Markdown
Contributor Author

vapopov commented Dec 2, 2024

would appreciate of review of this PR

Copy link
Copy Markdown
Contributor

@Joerger Joerger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, approach seems reasonable. Just left a suggestion for the naming.

Comment thread tool/tctl/common/access_request_command.go Outdated
@vapopov vapopov force-pushed the vapopov/reorgonize-tctl-commands branch from 0569781 to c68f24f Compare December 6, 2024 01:34
@vapopov
Copy link
Copy Markdown
Contributor Author

vapopov commented Dec 9, 2024

one more review by any chance

@vapopov vapopov requested a review from espadolini December 11, 2024 16:56
Copy link
Copy Markdown
Contributor

@hugoShaka hugoShaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once comments are resolved

Comment thread tool/tctl/common/client/auth.go
Comment thread tool/tctl/common/client/auth.go Outdated
Comment thread tool/tctl/common/admin_action_test.go Outdated
Comment thread tool/tctl/common/fido2.go
Comment on lines +38 to +39
func (c *fido2Command) TryRun(ctx context.Context, cmd string, _ commonclient.InitFunc) (match bool, err error) {
return c.impl.TryRun(ctx, cmd)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR makes the fido2 command work even without a valid client, nice :)

Comment thread tool/tctl/common/auth_command.go Outdated
Comment thread tool/tctl/common/plugin/plugins_command.go Outdated
@vapopov vapopov force-pushed the vapopov/reorgonize-tctl-commands branch from 70123e6 to 4b1e596 Compare December 17, 2024 19:52
@vapopov vapopov changed the title Reorganize tctl commands to have commands not required auth client Reorganize tctl commands to not require an auth client by default Dec 17, 2024
@vapopov vapopov added this pull request to the merge queue Dec 17, 2024
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Dec 17, 2024
@vapopov vapopov added this pull request to the merge queue Dec 17, 2024
Merged via the queue into master with commit 45f29a8 Dec 17, 2024
@vapopov vapopov deleted the vapopov/reorgonize-tctl-commands branch December 17, 2024 21:13
vapopov added a commit that referenced this pull request Jan 10, 2025
…8894)

* Reorganize tctl commands to have commands not required auth client

* Replace auth client with lazy loading approach

* Fix linter warning

* Replace camel case in import alias
Replace logrus to use slog

* Rename close function

* Refactor plugin commands to use interface of auth client and plugin client
Code review changes

* Refactor workload identity commands

* Add access to global config for the commands

* Add test checking all tctl commands match process

* Fix golangci-lint warnings
vapopov added a commit that referenced this pull request Jan 11, 2025
…8894)

* Reorganize tctl commands to have commands not required auth client

* Replace auth client with lazy loading approach

* Fix linter warning

* Replace camel case in import alias
Replace logrus to use slog

* Rename close function

* Refactor plugin commands to use interface of auth client and plugin client
Code review changes

* Refactor workload identity commands

* Add access to global config for the commands

* Add test checking all tctl commands match process

* Fix golangci-lint warnings
github-merge-queue Bot pushed a commit that referenced this pull request Jan 15, 2025
…8894) (#50966)

* Reorganize tctl commands to have commands not required auth client

* Replace auth client with lazy loading approach

* Fix linter warning

* Replace camel case in import alias
Replace logrus to use slog

* Rename close function

* Refactor plugin commands to use interface of auth client and plugin client
Code review changes

* Refactor workload identity commands

* Add access to global config for the commands

* Add test checking all tctl commands match process

* Fix golangci-lint warnings
github-merge-queue Bot pushed a commit that referenced this pull request Jan 15, 2025
…8894) (#50966)

* Reorganize tctl commands to have commands not required auth client

* Replace auth client with lazy loading approach

* Fix linter warning

* Replace camel case in import alias
Replace logrus to use slog

* Rename close function

* Refactor plugin commands to use interface of auth client and plugin client
Code review changes

* Refactor workload identity commands

* Add access to global config for the commands

* Add test checking all tctl commands match process

* Fix golangci-lint warnings
github-merge-queue Bot pushed a commit that referenced this pull request Jan 23, 2025
…8894) (#50968)

* Reorganize tctl commands to have commands not required auth client

* Replace auth client with lazy loading approach

* Fix linter warning

* Replace camel case in import alias
Replace logrus to use slog

* Rename close function

* Refactor plugin commands to use interface of auth client and plugin client
Code review changes

* Refactor workload identity commands

* Add access to global config for the commands

* Add test checking all tctl commands match process

* Fix golangci-lint warnings
carloscastrojumo pushed a commit to carloscastrojumo/teleport that referenced this pull request Feb 19, 2025
…avitational#48894)

* Reorganize tctl commands to have commands not required auth client

* Replace auth client with lazy loading approach

* Fix linter warning

* Replace camel case in import alias
Replace logrus to use slog

* Rename close function

* Refactor plugin commands to use interface of auth client and plugin client
Code review changes

* Refactor workload identity commands

* Add access to global config for the commands

* Add test checking all tctl commands match process

* Fix golangci-lint warnings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog Indicates that a PR does not require a changelog entry size/sm tctl tctl - Teleport admin tool tsh tsh - Teleport's command line tool for logging into nodes running Teleport.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants